package com.licq.ldoc.parser.impl.annotation;

import java.lang.annotation.Annotation;

import com.licq.ldoc.domain.Attribute;
import com.licq.ldoc.domain.AttributeType;
import com.licq.ldoc.domain.Element;
import com.licq.ldoc.domain.Occurrencies;
import com.licq.ldoc.parser.AnnotationParsee;

public class NotNullAnnotationParsee extends AnnotationParsee {

	public NotNullAnnotationParsee(AnnotationParsee successor) {
		super(successor);
	}

	@Override
	protected void doParse(Element element, Annotation annotation) {
		element.setRequired(true);
		if (element.getOccurrences() == Occurrencies.ZERO_OR_ONCE) {
			element.setOccurrences(Occurrencies.ONLY_ONCE);
		}
	}
	
	@Override
	protected void doParse(Attribute attribute, Annotation annotation) {
		attribute.setRequired(true);
		AttributeType type = attribute.getType();
		if (!AttributeType.isWrapperType(type)
				&& !AttributeType.isMapperType(type)) {
			attribute.setOccurrences(Occurrencies.ONLY_ONCE);
		}
	}

}
